package com.parfinex.java.phase1.module2.code.array;

import java.util.Scanner;

public class PrintArray {
    public static void main(String[] args){
        //定义一个长度为[16][16]的整型二维数组并输入或指定所有位置的元素值
        int[][] seeArray = new int[16][16];
        Scanner sc = new Scanner(System.in);
        for (int i=0;i<=15;i++){
            for (int j =0; j<=15; j++){
                System.out.print("请输入["+i+"] ["+j+"]=");
                seeArray[i][j] = sc.nextInt();
            }
        }
        sc.close();
        //按行求和，并输出
        for (int i=0; i<=15;i++){
            int rowSum = 0;
            for(int j =0; j<=15; j++){
                rowSum += seeArray[i][j];
            }
            System.out.println("第"+i+"行的求和："+rowSum);
        }
        //按列求各，并输出
        for (int j=0; j<=15 ;j++){
            int lineSum= 0;
            for (int i=0 ;i <=15 ;i++){
                lineSum += seeArray[i][j];
            }
            System.out.println("第"+j+"列的求和："+lineSum);
        }
        //按左上角到右下角，行和列的编号相同时，累加
        //按右上角到左下角，行和列的编号相加=15，累加
        int leftTopSum =0;
        int rightTopSum =0;
        for (int i=0; i<=15;i++){
            for (int j=0; j<=15;j++){
                if (i==j) leftTopSum +=seeArray[i][j];
                if (15==(i+j)) rightTopSum += seeArray[i][j];

            }
        }
        System.out.println("从左上角到右下角的求和值："+leftTopSum);
        System.out.println("从右上角到左下角的求和值："+rightTopSum);
    }


}
